<script setup>

import newsApi from '@/api/newsApi';
import {defineProps,ref} from 'vue'
defineProps({
  newsList:{
    type:Object,
    required:true
  }
})

//获取内容数据
const newsContent= ref([])
const getContent = async (id) =>{
  try {
    const res = await newsApi.newsContent(id)
    console.log(res);
    newsContent.value = res.data  // 将数据赋值给 newsContent
    console.log(newsContent.value);  // 可以在控制台查看数据
  } catch (error) {
    console.error('Error fetching news:', error);
  }
}

</script>

<template>
  <div>
    <div class="card" v-for="item in newsList" :key="item.id" @click="getContent(item.id)">
        <div class="card-left">
            <div class="title">{{ item.title }}</div>
            <div class="date">{{ item.date.year }}年{{ item.date.month }}月{{ item.date.day }}日</div>
        </div>
      <div class="card-right">
        <img :src="item.picList[0]" alt="">
      </div>
      
      
    </div>
  </div>
</template>

<style lang="less" scoped>
.card{
height: 100px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    
    border-bottom: 1px solid black;
    padding: 8px 0;
    .card-left{
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }
    
}
img{
        box-sizing: border-box;
        flex-shrink: 0;
        
        height: 80px;
    }
</style>